/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>商家结算管理</h3>
        <h5>网站系统商家结算索引与管理</h5>
      </div>
    </div>
    <div
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>商家订单按时自动结算</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>

    <div class="mDiv">
      <div class="ftitle">
        <h3>商家结算列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-date-picker
          v-model="dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          size="small"
        ></el-date-picker>
        <el-input
          class="searchinput"
          v-model="storeName"
          width="10"
          size="small"
          placeholder="店铺名称"
          clearable
        />
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>

    <div class="tablebox">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column label="记录ID" prop="id" width="80"></el-table-column>
        <el-table-column label="店铺id" prop="store_id" width="80"></el-table-column>
        <el-table-column label="店铺名称" prop="store_name" width="150"></el-table-column>
        <el-table-column label="开始时间" width="150">
          <template slot-scope="scope">{{scope.row.start_date | datefmtAll}}</template>
        </el-table-column>
        <el-table-column label="结束时间" width="150">
          <template slot-scope="scope">{{scope.row.end_date | datefmtAll}}</template>
        </el-table-column>
        <el-table-column label="订单商品金额" width="120">
          <template slot-scope="scope">{{scope.row.order_totals.toFixed(2)}}</template>
        </el-table-column>
        <el-table-column label="运费" width="100">
          <template slot-scope="scope">{{scope.row.shipping_totals.toFixed(2)}}</template>
        </el-table-column>
        <el-table-column label="积分金额" width="100">
          <template slot-scope="scope">{{scope.row.give_integral.toFixed(2)}}</template>
        </el-table-column>
        <el-table-column label="分销金额" width="100">
          <template slot-scope="scope">{{scope.row.distribut.toFixed(2)}}</template>
        </el-table-column>
        <el-table-column label="优惠价" width="100">
          <template slot-scope="scope">{{scope.row.order_prom_amount.toFixed(2)}}</template>
        </el-table-column>
        <el-table-column label="优惠券抵扣" width="100">
          <template slot-scope="scope">{{scope.row.coupon_price.toFixed(2)}}</template>
        </el-table-column>
        <el-table-column label="本期应结" width="100">
          <template slot-scope="scope">{{scope.row.result_totals.toFixed(2)}}</template>
        </el-table-column>
        <el-table-column label="创建记录日期" width="150">
          <template slot-scope="scope">{{scope.row.create_date | datefmtAll}}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button size="small" @click="orders(scope.row.id)" icon="el-icon-search">查看订单</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getOrderStatis } from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10,
      dateRange: null,
      storeName: null
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      var params = {
        store_name: this.storeName,
        page: this.currentPage,
        size: this.pageSize
      };
      if (this.dateRange) {
        params.start_time = this.dateRange[0] / 1000;
        params.end_time = this.dateRange[1] / 1000 + 86400;
      }
      getOrderStatis(params).then(function(res) {
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    orders(id) {
      this.$router.push({
        name: "orders",
        params: {
          id: id
        }
      });
    },
    refresh() {
      this.getPage();
      this.$message.success("刷新成功！");
    }
  }
};
</script>

<style scoped>
.searchinput {
  width: auto;
}
</style>
